package com.delivery.www.service.ServiceImpl;

import com.delivery.www.dao.CartDishDao;
import com.delivery.www.po.Cart;
import com.delivery.www.po.Dish;
import com.delivery.www.dao.DaoImpl.CartDishDaoImpl;
import com.delivery.www.service.CartDishService;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 12970
 */
public class CartDishServiceImpl implements CartDishService {
    private final CartDishDao cartDishDao = new CartDishDaoImpl();

    @Override
    public boolean addCartDish(int cartId, int dishId) {
        if (cartId <= 0 && dishId <= 0) {
            return false;
        } else {
            return cartDishDao.addCartDish(cartId, dishId) > 0;
        }
    }

    @Override
    public List<List<Dish>> getCartDish(List<Cart> carts) {
        if (carts==null){
            return null;
        }else {
            List<Integer> integers1 = new ArrayList<>();
            for (Cart cart : carts) {
                integers1.add(cart.getCartId());
            }
            List<List<Integer>> list = cartDishDao.getCartDish(integers1);
            return cartDishDao.getCartAllDish(list);
        }
    }


}
